//
//  HomeViewController.m
//  Civacrm
//
//  Created by 王桂敏 on 2017/2/4.
//  Copyright © 2017年 王桂敏. All rights reserved.
//

#import "HomeViewController.h"
#import "BannerView.h"
#import "BannerModel.h"
#import "SubTabModel.h"
#import "ListTableViewCell.h"
#import "CollectionView.h"
#import "TabModel.h"
#import "IconModel.h"
#import "CourseModel.h"
#import "CourseViewController.h"
#import "WithoutDataTableViewCell.h"
#import "BottomView.h"
#import "IntroductionsView.h"
#import "UserInfoModel.h"
#import "TaskView.h"
#import "CourseDetailViewController.h"

static NSString *CourseIdentifier = @"CourseCell";
static NSString *ListIdentifier = @"ListCell";
@interface HomeViewController ()<BannerViewDelegate,CollectionViewDelegate>

@property (nonatomic,strong) BannerView *adScrollView;

@property (nonatomic,strong) NSMutableArray *bannerDataSource;

@property (nonatomic,strong) NSMutableArray *bannerImageArray;

@property (nonatomic,strong) CollectionView *iconTabCollectView;

@property (nonatomic,strong) CollectionView *tabCollectView;

@property (nonatomic,strong) CollectionView *coursetabCollectView;

@property (nonatomic,strong) CollectionView *subTabCollectView;

@property (nonatomic,strong) TaskView *taskView;

@property (nonatomic,strong) UIView *sectionView;

@property (nonatomic,strong) UIView *sectionView0;

@property (nonatomic,strong) UIView *tableHeaderView;

@property (nonatomic,strong) UIButton *detailButton;

@property (nonatomic,strong) NSMutableArray *listDataSource;

@property (nonatomic,strong) NSMutableArray *courseDataSource;

@property (nonatomic,strong) NSMutableArray *courseTabDataSource;

@property (nonatomic,strong) NSMutableArray *iconTabDataSource;

@property (nonatomic,strong) NSMutableArray *subTabDataSource;

@property (nonatomic,strong) NSMutableArray *tabDataSource;

@property (nonatomic,assign) NSInteger tabIndex;

@property (nonatomic,assign) NSInteger subTabIndex;

@property (nonatomic,strong) NSIndexPath *seletIndexPath;

@property (nonatomic,assign) BOOL temp;

@property (nonatomic,copy) NSString * introductionString;

@property (nonatomic,assign) BOOL net0;

@property (nonatomic,assign) BOOL net1;

@property (nonatomic,strong) UILabel *lineLable;

@end

@implementation HomeViewController

- (TaskView *)taskView{
    if (!_taskView) {
        self.taskView = [[TaskView alloc] init];
    }
    return _taskView;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initNavigation];
    [self initData];
    [self initView];
    [self initNetWork];
    [self initNetWorkOfDataStatisticsTab];
    
}
- (void)initNavigation{
    self.title = @"Civa支撑";
}
- (void)initData{
    self.tabIndex = 0;
    self.subTabIndex = 0;
    self.pageNo = 2;
    self.pageSize = 10;
    self.bannerDataSource = [NSMutableArray array];
    self.bannerImageArray = [NSMutableArray array];
    
    self.listDataSource = [NSMutableArray arrayWithObject:[NSMutableArray arrayWithObject:[NSMutableArray array]]];
    
    self.tabDataSource =  [NSMutableArray array];
    self.subTabDataSource = [NSMutableArray array];
    self.iconTabDataSource = [NSMutableArray array];
    self.courseDataSource = [NSMutableArray array];
    self.courseTabDataSource = [NSMutableArray array];
}
- (void)initView{
    
    self.tableView.frame = CGRectMake(0, 0, self.view.width, self.view.height - 64 - 49 - h(80));
    self.tableView.backgroundColor = ClearColor;
    self.tableView.mj_header = self.header;
    self.tableView.mj_footer = self.footer;//下拉加载暂时去除
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CourseIdentifier];
    [self.tableView registerClass:[ListTableViewCell class] forCellReuseIdentifier:ListIdentifier];
    [self.tableView registerClass:[WithoutDataTableViewCell class] forCellReuseIdentifier:@"noData"];
    
    //  表头
    self.adScrollView = [[BannerView alloc] initPageViewFrame:CGRectMake(0, 0, kScreenWidth, h(220))];
    self.adScrollView.isSDWebImage = YES;
    self.adScrollView.iDisplayTime = 3.0;
    self.adScrollView.delegate = self;
    
    
    self.iconTabCollectView = [[CollectionView alloc] initViewWithType:CollectionViewType3 frame:CGRectMake(0, self.adScrollView.height, kScreenWidth, h(164))];
    self.iconTabCollectView.delegate = self;

    self.tableHeaderView = [UIView viewWithFrame:CGRectMake(0, 0, kScreenWidth, self.adScrollView.height + self.iconTabCollectView.height) bgColor:GlobalBgColor];
    
    [self.tableHeaderView addSubview:self.adScrollView];
    [self.tableHeaderView addSubview:self.iconTabCollectView];
    
    self.lineLable = [UILabel labelWithTitle:nil frame:CGRectMake(0, self.tableHeaderView.height - 0.2, kScreenWidth, 0.2) font:font(12) textColor:nil bgColor:GlobalGray];
  
    
    [self.tableHeaderView addSubview:self.lineLable];
    self.tableView.tableHeaderView = self.tableHeaderView;
    
    
  //    第1区
    self.sectionView = [UIView viewWithFrame:CGRectMake(0, 0, kScreenWidth, h(118)) bgColor:WhiteColor];
    self.tabCollectView = [[CollectionView alloc] initViewWithType:CollectionViewType1 frame:CGRectMake(0, 0, kScreenWidth, h(42))];
    self.tabCollectView.delegate = self;
    [self.sectionView addSubview:self.tabCollectView];
    [self.sectionView addLineWithLineWidth:0.2 startPoint:CGPointMake(0, 0) endPoint:CGPointMake(kScreenWidth, 0) lineColor:GlobalGray];
    
    //  说明按钮
    self.detailButton = [UIButton buttonOfImageForNormalWithImage:@"icon_shuoming" frame:CGRectMake(kScreenWidth - w(10) - w(62), 0, w(62), h(42)) target:self action:@selector(handleDetailButtonAction)];
    self.detailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
    [self.tabCollectView addSubview:self.detailButton];
    
    self.subTabCollectView = [[CollectionView alloc] initViewWithType:CollectionViewType2 frame:CGRectMake(0, h(42), kScreenWidth, h(76))];
    self.subTabCollectView.delegate = self;
    [self.sectionView addSubview:self.subTabCollectView];
    [self.sectionView addLineWithLineWidth:0.2 startPoint:CGPointMake(0, self.sectionView.height - 0.2) endPoint:CGPointMake(kScreenWidth, self.sectionView.height - 0.2) lineColor:GlobalGray];

    //  数据为空
    self.nillView = [[NillView alloc] initViewWithType:NillViewType0 frame:self.view.bounds];
    @weakify(self);
    self.nillView.blockOfbackground = ^(){
        @strongify(self);
        if (!self.net0) {
            [self initNetWork];
        }
        if (!self.net1) {
            [self initNetWorkOfDataStatisticsTab];
        }
        
    };
    [self.view addSubview:self.nillView];


}
#pragma mark - buttonAction
//  说明按钮
- (void)handleDetailButtonAction{
    
    IntroductionsView * myView = [[IntroductionsView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    [myView creatView];
    myView.contentView.text = self.introductionString;
    [self.view addSubview:myView];
    
}



#pragma mark - CollectionViewDelegate -
- (void)collectionView:(UICollectionView *)collectionView didSelect:(NSInteger)index type:(CollectionViewType)type{
    switch (type) {
        case CollectionViewType1:
        {
//            if (self.tabIndex != index) {
//                self.tabIndex = index;
//                self.subTabIndex = 0;
//            }
            return;
            
        }
            break;
        case CollectionViewType2:
        {
            self.subTabIndex = index;
            
        }
            break;
        case CollectionViewType3:
        {
            if ([[(IconModel *)self.iconTabDataSource[index] value] containsString:@"kc_"]) {
                CourseModel *model = [[CourseModel alloc] init];
                model.taskModel.taskId = [(IconModel *)self.iconTabDataSource[index] value];
                CourseDetailViewController *VC = [[CourseDetailViewController alloc] init];
                VC.webURL = [NSString stringWithFormat:@"%@&uId=%@&taskId=%@",H5url,self.userID,[model.taskModel.taskId stringByReplacingOccurrencesOfString:@"kc_" withString:@""]];
                VC.model = model;
                [self.navigationController pushViewController:VC animated:YES];
            } else if ([[(IconModel *)self.iconTabDataSource[index] value] containsString:@"sp_"]){
                CourseModel *model = [[CourseModel alloc] init];
                model.taskModel.taskId = [(IconModel *)self.iconTabDataSource[index] value];
                CourseDetailViewController *VC = [[CourseDetailViewController alloc] init];
                VC.webURL = [NSString stringWithFormat:@"%@&uId=%@&taskId=%@",H5url,self.userID,model.taskModel.taskId];
                [self.navigationController pushViewController:VC animated:YES];
            } else {
                [self showAlertWithTitle:nil message:@"新模块开发中...\n敬请期待!!" actionNameArray:@[@"确定"] action:^(NSInteger index) {
                    
                } VC:self];
            }
            
        }
            break;
            
        default:
            break;
    }
    
    if ([(NSArray *)self.listDataSource[self.tabIndex][self.subTabIndex] count]) {
        self.pageNo = 1 + [(NSArray *)self.listDataSource[self.tabIndex][self.subTabIndex] count] / self.pageSize + ([(NSArray *)self.listDataSource[self.tabIndex][self.subTabIndex] count] % self.pageSize) ? 1 : 0;
    } else {
        self.pageNo = 1;
    }
    if (self.pageNo == 1 && ![(NSArray *)self.listDataSource[self.tabIndex][self.subTabIndex] count]) {
        [self initNetWorkOfGetRankingList];
    }

    CGRect rect = [self.adScrollView convertRect:self.adScrollView.superview.frame toView:self.view];
    if (rect.origin.y < -(h(164) + h(422) + h(62)) ) {
         self.temp = YES;
    } else {
        self.temp = NO;
    }
    [self.tableView reloadData];
    if (self.temp == YES) {
        self.tableView.contentOffset = CGPointMake(0, h(220) + h(164) + ((self.courseDataSource.count / self.taskView.collectionView.col + (self.courseDataSource.count%self.taskView.collectionView.col ? 1 : 0)) * h(211)) + h(62));
    }
    
}
#pragma mark - BannerViewDelegate -
-(void)didSelectPageViewWithNumber:(NSInteger)selectNumber{
    if (self.bannerDataSource.count && ![[self.bannerDataSource[selectNumber] valueContent] isBlank]) {
        CourseModel *model = [[CourseModel alloc] init];
        model.taskModel.taskId = [self.bannerDataSource[selectNumber] valueContent];
        CourseDetailViewController *VC = [[CourseDetailViewController alloc] init];
        VC.webURL = [NSString stringWithFormat:@"%@&uId=%@&taskId=%@",H5url,self.userID,[model.taskModel.taskId stringByReplacingOccurrencesOfString:@"kc_" withString:@""]];
        VC.model = model;
        [self.navigationController pushViewController:VC animated:YES];
    }
}
#pragma mark - UITableViewDataSource&UITableViewDelegate -
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 0) {
        
    } else {
        if ([(NSMutableArray *)self.listDataSource[self.tabIndex][self.subTabIndex] count]) {
            if (self.seletIndexPath && self.seletIndexPath != indexPath) {
                ListTableViewCell *cell = [tableView cellForRowAtIndexPath:self.seletIndexPath];
                [cell.nameLabel stopTimer];
            }
            ListTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
            [cell.nameLabel beginTimer];
            self.seletIndexPath = indexPath;
        }
    }
    
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    switch (section) {
        case 0:
        {
            return 1;
        }
            break;
        case 1:
        {
            return [(NSMutableArray *)self.listDataSource[self.tabIndex][self.subTabIndex] count] ? [(NSMutableArray *)self.listDataSource[self.tabIndex][self.subTabIndex] count] : 1;
        }
            break;
            
        default:
            return 0;
            break;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.section) {
        case 0:
        {
            return (self.courseDataSource.count / self.taskView.collectionView.col + (self.courseDataSource.count%self.taskView.collectionView.col ? 1 : 0)) * h(211);
        }
            break;
        case 1:
        {
            return [(NSMutableArray *)self.listDataSource[self.tabIndex][self.subTabIndex] count] ? h(140) : self.tableView.height - h(118) - self.adScrollView.height;
        }
            break;
            
        default:
            return 0;
            break;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.section) {
        case 0:
        {
            UITableViewCell *cell =  [tableView dequeueReusableCellWithIdentifier:CourseIdentifier];
            [cell addSubview:self.taskView.collectionView];
            return cell;
        }
            break;
        case 1:
        {
            if ([(NSMutableArray *)self.listDataSource[self.tabIndex][self.subTabIndex] count]) {
                ListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ListIdentifier];
                [cell configCellWithModel:self.listDataSource[self.tabIndex][self.subTabIndex][indexPath.row]];
                cell.selectionStyle = UITableViewCellSelectionStyleDefault;
                return cell;
            } else {
                WithoutDataTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"noData"];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }
        }
            break;
            
        default:
            return nil;
            break;
    }
    
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return self.taskView.tabView;
    } else{
        return self.sectionView;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        return h(62);
    } else{
        return h(118);
    }
}

#pragma mark - networkAndNetworkDelegate -
//  banner图
- (void)initNetWork{
    
    self.params[@"uId"] = self.userID;
    [self.manager postWithURL:NET_HOMEPAGE param:self.params delegate:self isEncrypt:NO type:NetWorkingType0];
    
}
//  首次排行榜数据
- (void)initNetWorkOfDataStatisticsTab{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"uId"] = self.userID;
    [self showIndeterminate];
    [self.manager postWithURL:NET_DATASTATISTICSTAB param:param delegate:self isEncrypt:NO type:NetWorkingType1];
    
}

//  排行榜数据
- (void)initNetWorkOfGetRankingList{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"type"] = [self.tabDataSource[self.tabIndex] tid];
    param[@"countType"] = [self.subTabDataSource[self.tabIndex][self.subTabIndex] tid];
    param[@"pageNo"] = [NSString stringWithFormat:@"%@",@(self.pageNo)];
    param[@"pageSize"] = [NSString stringWithFormat:@"%@",@(self.pageSize)];
    [self showIndeterminate];
    [self.manager postWithURL:NET_GETRANKINGLIST param:param delegate:self isEncrypt:NO type:NetWorkingType2];
    
}


- (void)networkingHandleSuccess:(NetworkingHandle *)handle parameters:(NSDictionary *)parameters responseObject:(id)responseObject type:(NetWorkingType)type{
    [self endRefresh];
    [self hideHud];
    switch (type) {
        case NetWorkingType0:
        {
            self.net0 = YES;
            if (self.net1) {
                [self.nillView removeFromSuperview];
            }
            //  banner
            NSArray *dataArray = responseObject[@"banner"];
            
            [self.bannerDataSource removeAllObjects];
            [self.bannerImageArray removeAllObjects];
            
            for (int i = 0; i < [dataArray count]; i++) {
                BannerModel *model = [[BannerModel alloc] init];
                [model setValuesForKeysWithDictionary:dataArray[i]];
                [self.bannerDataSource addObject:model];
                
                [self.bannerImageArray addObject:model.img];
            }
            
            [self.adScrollView setImageArray:self.bannerImageArray];
           
            
            //  横屏课程
            NSArray *hblistArray = responseObject[@"hblist"];
            
            [self.iconTabDataSource removeAllObjects];
            
            for (int i = 0; i < [hblistArray count]; i++) {
                IconModel *model = [[IconModel alloc] init];
                [model setValuesForKeysWithDictionary:hblistArray[i]];
                [self.iconTabDataSource addObject:model];
            }
            
            [self.iconTabCollectView setDataSource:self.iconTabDataSource];
            self.tableHeaderView.height = self.adScrollView.height + self.iconTabCollectView.height;
            self.lineLable.y = self.tableHeaderView.height - 0.2;
            self.tableView.tableHeaderView = self.tableHeaderView;
            
            //  taskInfo
            NSArray *tasklistArray = responseObject[@"taskInfo"][@"Tasklist"];
            
            [self.courseDataSource removeAllObjects];
            
            for (int i = 0; i < [tasklistArray count]; i++) {
                CourseModel *model = [[CourseModel alloc] init];
                [model setValuesForKeysWithDictionary:tasklistArray[i]];
                [self.courseDataSource addObject:model];
            }
            [self.taskView configCollectViewWithRow:[responseObject[@"taskInfo"][@"rowCnt"] integerValue] col:[responseObject[@"taskInfo"][@"colCnt"] integerValue] dataSource:self.courseDataSource];
            [self.taskView configTabViewWithTitle:@"Civa支撑"];
//            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
            [self.tableView reloadData];
            
            
        }
            break;
        case NetWorkingType1:
        {
            self.net1 = YES;
            if (self.net0) {
                [self.nillView removeFromSuperview];
            }
            
            [self.listDataSource removeAllObjects];
            [self.subTabDataSource removeAllObjects];
            [self.tabDataSource removeAllObjects];
            NSString * tempString = responseObject[@"pmdVal"];
            if (tempString.length > 0) {
                
                NSArray * array = [tempString componentsSeparatedByString:@","];
                if (array.count > 0) {
                    self.activeString = array[0];
                    self.payforString = array[1];
                }
                
            }else
            {
                self.activeString = @"学生激活：暂无";
                self.payforString = @"学生付费：暂无";
                
            }
            
            NSString * detailString = responseObject[@"dayRinkingContent"];
            if (detailString.length) {
                self.introductionString = detailString;
            }else
            {
                self.introductionString = @"\n\n\n 暂无说明";
            }
            BottomView * bottomView = [BottomView initBottomViewWithFrame:CGRectMake(0, kScreenHeight - 49 - 64 - h(80), kScreenWidth, h(80)) andActivateNumString:self.activeString andPayForNumString:self.payforString];
            [self.view addSubview:bottomView];
            
            //  一级tab数据
            NSArray *tabDataArray = responseObject[@"tab"];
            
            TabModel *model = [[TabModel alloc] init];
            model.name = @"Civa支撑";
            [self.courseTabDataSource addObject:model];
            
            for (int i = 0; i < [tabDataArray count]; i++) {
                TabModel *model = [[TabModel alloc] init];
                [model setValuesForKeysWithDictionary:tabDataArray[i]];
                [self.tabDataSource addObject:model];
                
                NSMutableArray *array = [NSMutableArray array];
                [self.listDataSource addObject:array];
                NSMutableArray *array1 = [NSMutableArray array];
                [self.subTabDataSource addObject:array1];
                
                //  二级tab数据
                NSArray *dataArray = responseObject[@"tab"][i][@"subTab"];
                
                for (int j = 0; j < [dataArray count]; j++) {
                    SubTabModel *model = [[SubTabModel alloc] init];
                    [model setValuesForKeysWithDictionary:dataArray[j]];
                    [self.subTabDataSource[i] addObject:model];
                    
                    NSMutableArray *array = [NSMutableArray array];
                    [self.listDataSource[i] addObject:array];
                }
            }
            
            //  第一页数据
            NSArray *listDataArray = responseObject[@"list"];
            
            for (int i = 0; i < [listDataArray count]; i++) {
                ListModel *model = [[ListModel alloc] init];
                [model setValuesForKeysWithDictionary:listDataArray[i]];
                
                if (i == 0) {
                    model.number = 1;
                    model.type = ListModelType0;
                } else {
                    if ([model.count isEqualToString:[(ListModel *)[self.listDataSource[self.tabIndex][self.subTabIndex] lastObject] count]]) {
                        model.number = [(ListModel *)[self.listDataSource[self.tabIndex][self.subTabIndex] lastObject] number];
                    } else {
                        model.number = [(NSMutableArray *)self.listDataSource[self.tabIndex][self.subTabIndex] count] + 1;
                    }
                    
                    if ([model.count isEqualToString:[(ListModel *)[self.listDataSource[self.tabIndex][self.subTabIndex] lastObject] count]]) {
                        model.type = [(ListModel *)[self.listDataSource[self.tabIndex][self.subTabIndex] lastObject] type];
                    } else if([(ListModel *)[self.listDataSource[self.tabIndex][self.subTabIndex] lastObject] type] < ListModelType3){
                        if (i > 2) {
                            model.type = ListModelType3;
                        } else {
                            model.type = [(ListModel *)[self.listDataSource[self.tabIndex][self.subTabIndex] lastObject] type] + 1;
                        }
                    } else {
                        model.type = ListModelType3;
                    }
                }
                [self.listDataSource[self.tabIndex][self.subTabIndex] addObject:model];
            
            }
            
            if (listDataArray.count < self.pageSize) {
                [self.tableView.mj_footer endRefreshingWithNoMoreData];
            }
            [self.coursetabCollectView setDataSource:self.courseTabDataSource];
            [self.tabCollectView setDataSource:self.tabDataSource];
            [self.subTabCollectView setDataSource:self.subTabDataSource[0]];
            [self.tableView reloadData];
        }
            break;
        case NetWorkingType2:
        {
            
            if ([parameters[@"pageNo"] integerValue] == 1) {
                [self.listDataSource[self.tabIndex][self.subTabIndex] removeAllObjects];
            }
            //  排行榜数据
            NSArray *listDataArray = responseObject;
            
            for (int i = 0; i < [listDataArray count]; i++) {
                ListModel *model = [[ListModel alloc] init];
                [model setValuesForKeysWithDictionary:listDataArray[i]];

                if (i == 0 && self.pageNo == 1) {
                    model.number = 1;
                    model.type = ListModelType0;
                } else {
                    if ([model.count isEqualToString:[(ListModel *)[self.listDataSource[self.tabIndex][self.subTabIndex] lastObject] count]]) {
                        model.number = [(ListModel *)[self.listDataSource[self.tabIndex][self.subTabIndex] lastObject] number];
                    } else {
                        model.number = [(NSMutableArray *)self.listDataSource[self.tabIndex][self.subTabIndex] count] + 1;
                    }
                    
                    if ([model.count isEqualToString:[(ListModel *)[self.listDataSource[self.tabIndex][self.subTabIndex] lastObject] count]]) {
                        model.type = [(ListModel *)[self.listDataSource[self.tabIndex][self.subTabIndex] lastObject] type];
                    } else if([(ListModel *)[self.listDataSource[self.tabIndex][self.subTabIndex] lastObject] type] < ListModelType3){
                        if (i > 2) {
                            model.type = ListModelType3;
                        } else {
                            model.type = [(ListModel *)[self.listDataSource[self.tabIndex][self.subTabIndex] lastObject] type] + 1;
                        }
                        
                    } else {
                        model.type = ListModelType3;
                    }
                }
                
                [self.listDataSource[self.tabIndex][self.subTabIndex] addObject:model];
                
            }
            self.pageNo++;
            if (listDataArray.count < self.pageSize) {
                [self.tableView.mj_footer endRefreshingWithNoMoreData];
            }
            
            [self.tabCollectView setDataSource:self.tabDataSource];
            [self.subTabCollectView setDataSource:self.subTabDataSource[0]];
            [self.tableView reloadData];
        }
            break;

            
        default:
            break;
    }
    
}

- (void)networkingHandlefail:(NetworkingHandle *)handle type:(NetWorkingType)type{
    [self endRefresh];
    [self hideHud];
    switch (type) {
        case NetWorkingType1:
        {
            
        }
            break;
            
        default:
            break;
    }
}

- (void)networkingHandleWarning:(NetworkingHandle *)handle responseObject:(id)responseObject type:(NetWorkingType)type{
    [self endRefresh];
    [self hideHud];
    switch (type) {
        case NetWorkingType1:
        {
            
        }
            break;
            
        default:
            break;
    }
    
}

#pragma mark 下拉刷新和上拉加载
- (void)handleHeaderRefreshingAction{

    self.tabIndex = 0;
    self.subTabIndex = 0;
    self.pageNo = 2;
    
    [self.bannerDataSource removeAllObjects];
    [self.bannerImageArray removeAllObjects];
    [self.listDataSource removeAllObjects];
    [self.listDataSource addObject:[NSMutableArray arrayWithObject:[NSMutableArray array]]];
    [self.tabDataSource removeAllObjects];
    [self.subTabDataSource removeAllObjects];
    [self.iconTabDataSource removeAllObjects];
    [self.courseDataSource removeAllObjects];
    [self.courseTabDataSource removeAllObjects];
    
    [self.courseDataSource removeAllObjects];
    
    [self initNetWork];
    [self initNetWorkOfDataStatisticsTab];
}
- (void)handleFooterRefreshingAction{
    
    [self initNetWorkOfGetRankingList];
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
